<?php
include './config/config_global.php';
include './config/mysql.php';
include './config/mysql_func.php';
include './config/config_ucenter.php';
include './uc_client/client.php';

$mod = $_REQUEST['mod'];

if ( $mod == 'update_f_a' ){
	update_f_a();
}elseif ( $mod == 'show_f_a' ){
	show_f_a();
}elseif( $mod == 'getarea' ){
	getarea();
}elseif( $mod == 'login' ){
	login();
}

function update_f_a(){
	global $link;
	$dats = explode('|',$_POST['dat']);
	$sql = 'replace INTO `ultrax`.`pre_f_a` ( `fid` ,`aid`) VALUES ';
	$set = '';
	foreach ((array)$dats as $dat) {
		if ( $dat != '' ) list($f,$a) = explode(',',$dat);
		
		if ( $a != '') $set .= "({$f},{$a}),"; 
	}
	
	if ( $set != '' ){
		$set = substr( $set, 0, strlen($set)-1 );
	}
	
	$sql .= $set;
	$ret = mysql_query( $sql, $link);
	print_r( $ret );
}
function show_f_a(){
	global $link;

	$sql = 'SELECT * FROM pre_f_a';
	$result = mysql_query($sql, $link);
	$rows = fetch_all($result);
	foreach ( $rows as $row )
	{
		echo "f_a[{$row['fid']}] = '{$row['aid']}';";
	}	
}
function login(){
	list( $uid, $username, $password, $email ) = uc_user_login( mysql_escape_string($_POST['uname']), mysql_escape_string($_POST['pwd']) );
	if ( $uid > 0 ){
		setcookie("tt_username", $username, time()+3600*24*30); 
		setcookie("tt_email", $email, time()+3600*24*30);
	}
	$ucsynlogin = uc_user_synlogin($uid);
	$userinfo = uc_get_user($uid,1);

	global $link;	
	$sql = 'SELECT * FROM pre_common_member where uid = '.$uid;
	$result = mysql_query($sql, $link);
	$member = fetch_one($result);	
	
	$sql = 'SELECT * FROM pre_common_member_count where uid = '.$uid;
	$result = mysql_query($sql, $link);
	$member_count = fetch_one($result);	
	
	echo json_encode( array_merge( $member, $member_count ) );
}
